package com.hqd.ch03.v44.beans;

import com.hqd.ch03.v44.core.Ordered;

import java.beans.*;
import java.util.Collection;

public class SimpleBeanInfoFactory implements BeanInfoFactory, Ordered {

    @Override

    public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
        Collection<? extends PropertyDescriptor> pds =
                PropertyDescriptorUtils.determineBasicProperties(beanClass);

        return new SimpleBeanInfo() {
            @Override
            public BeanDescriptor getBeanDescriptor() {
                return new BeanDescriptor(beanClass);
            }

            @Override
            public PropertyDescriptor[] getPropertyDescriptors() {
                return pds.toArray(PropertyDescriptorUtils.EMPTY_PROPERTY_DESCRIPTOR_ARRAY);
            }
        };
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE - 1;
    }

}
